<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=0">
    <title>购物车</title>
    <script src="/js/shop/js/jquery.min.js"></script>
    <script src="/js/shop/js/shoppingcart.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" type="text/css" href="/js/shop/css/shoppingcart.css"/>

    <script src="/js/common.js"></script>
    <script src="/js/checkLogin.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>

    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategy.css"/>


    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/plugins/form/jquery.form.js"></script>
    <script>
        $(function () {
            $.ajaxSettings.traditional=true;
            $.get(baseUrl+"users/"+user.id+"/productByUsers",{pageSize:0},
                function (data) {
                $(".body").renderValues(data, {
                    'getHref': getHref
                });
                    //加的效果
                    $(".product-add").click(function(){
                        var n=$(this).prev().val();
                        var num=parseInt(n)+1;
                        if(num==99){ return;}
                        $(this).prev().val(num);
                        TotalPrice();
                    });
                    //减的效果
                    $(".product-jian").click(function(){
                        var n=$(this).next().val();
                        var num=parseInt(n)-1;
                        if(num==0){ return;}
                        $(this).next().val(num);
                        TotalPrice();
                    });
                    //选中商品
                    $(".product-ckb").click(function(){
                        $(this).children("em").toggleClass("product-xz");
                        var slproice = parseInt($(this).parents(".product-ckb").siblings().find(".product-num").val());//得到产品数量
                        TotalPrice();
                        productxz();
                    });
                    //结算功能
                    var productNumbers=[];
                    var productIds=[];
                    var carIds=[]

                    //删除产品
                    $(".product-del").click(function(){
                        if(confirm("您确定要删除当前商品？")){
                           var productCarId=$(this).siblings(".product-amount").find(".productCar-id").val();
                            $.post(baseUrl+"users/"+user.id+"/deleteCars",{productCarId:productCarId},function (data) {
                                if(data.success){
                                    $(document).dialog({
                                        titleShow: false,
                                        content: "移出成功"
                                    });
                                    window.location.reload();
                                }else {
                                    $(document).dialog({
                                        titleShow: false,
                                        content: "移出失败"+ data.errorMsg
                                    });
                                }
                            })
                        }
                        koncat();
                        TotalPrice();
                    });
                    $("#pay").click(function () {
                        //获取所有被选中商品的id和,数量
                        $(".product-em").each(function(){
                            if($(this).is(".product-xz")){
                                var slproice = parseInt($(this).parents(".product-ckb").siblings().find(".product-num").val());//得到产品数量
                                var carId = parseInt($(this).parents(".product-ckb").siblings().find(".productCar-id").val());//得到购物车订单id
                                var id = parseInt($(this).parents(".product-ckb").siblings().find(".product-id").val());//得到产品id
                                console.log(id);
                                productNumbers.push(slproice);
                                productIds.push(id);
                                carIds.push(carId);
                            }
                        });
                        //确定是否购买
                        var number = totalMoney.valueOf();
                        var json={
                            productNumber:productNumbers,
                            productId:productIds,
                            total:number,
                            carId:carIds
                        }
                        $(document).dialog({
                            type : 'confirm',
                            closeBtnShow: true,
                            content: "总共需要"+totalMoney+"积分,确定购买吗亲!",
                            onClickConfirmBtn: function(){
                                $.get(baseUrl+"/users/"+user.id+"/attendances/integrals",json,function (data) {
                                    if(data.success){
                                        $(document).dialog({
                                            titleShow: false,
                                            content: "购买成功"
                                        });
                                        window.location.reload();
                                    }else{
                                        $(document).dialog({
                                            type: 'confirm',
                                            style: 'android',
                                            titleText: '温馨提示:',
                                            content: "购买失败" + data.errorMsg,
                                            buttons: [
                                                {
                                                    name: '返回',
                                                    callback: function () {
                                                    }
                                                }
                                            ]
                                        });
                                    }
                                })
                            },
                            onClickCancelBtn : function(){

                            },
                            onClickCloseBtn  : function(){

                            }
                        });
                        console.log(totalMoney);
                    })
            })
        })
    </script>
    <style>
        .a4{color: white;font-size: 14px; margin-left:70px;}
        .a5{color: white;font-size: 18px; margin-left:80px;width: 100%;}
        a:hover {color:red }
    </style>
</head>
<body>
<div class="search-head" style="height: 0px;background-color:#2b2c33;">
    <div class="row nav-search" >
        <div class="col-2">
            <a href="javascript:window.history.go(-1);">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
    </div>
</div>
<div class="body" style="padding-top: 0px;">

    <div class="shop" style="background-color:#2b2c33;"><i></i><span class="a5">我的购物车<a href="order.html" class="a4">我的订单</a></span></div>
        <div class="product" render-loop="list">
                <div class="product-box">
                    <div class="product-ckb"><em class="product-em"></em></div>
                    <div class="product-sx">
                        <a render-key="list.product.id" render-fun="getHref" data-url="productData.html?id=">
                            <img render-src="list.product.imgUrl" class="product-img" />
                            <span class="product-name" render-html="list.product.name"></span>
                        </a>
                        <span class="product-price">¥&thinsp;<span class="price" render-html="list.product.price"></span></span>
                        <div class="product-amount">
                            <input type="hidden" name="id" class="product-id" render-value="list.product.id">
                            <input type="hidden" name="id" class="productCar-id" render-value="list.id">
                            <div class="product_gw">
                                <em class="product-jian">-</em>
                                <input type="text" value="1" class="product-num"/>
                                <em class="product-add">+</em>
                            </div>
                        </div>
                        <div class="product-del"><img src="/js/shop/img/deleteico.png"/></div>
                    </div>
                </div>
        </div>
    <div class="product-js">
        <div class="product-al">
            <div class="product-all">
                <em class=""></em>
            </div>
            <div class="all-xz"><span class="product-all-qx">全选</span><div class="all-sl" style="display: none;">(<span class="product-all-sl">0</span>)</div></div>
        </div>
        <a href="javaScript:;" class="product-sett product-sett-a" id="pay">结算</a>
        <div class="all-product"><span class="all-product-a">¥&thinsp;<span class="all-price"></span></span></div>
    </div>
</div>

<!--购物车空-->
<div class="kon-cat">
    <div class="catkon">
        <div class="kon-box">
            <div class="kon-hz">
                <img src="/js/shop/img/cart-air.png" />
                <span class="kon-wz">购物车什么都没有</span>
                <a href="###" class="kon-lj">去逛逛</a>
            </div>
        </div>
    </div>
</div>

</body>
</html>
